import { defineStore } from 'pinia'
export const useUserStore = defineStore('user', {
  state: () => ({
    lang: localStorage.getItem('lang') || 'en',
  }),

  getters: {
    // hasUser: (state) => !!state.user,
    // repoCount: (state) => state.repos.length
  },

  actions: {
    // async fetchUser(username) {
    //   this.loading = true
    //   this.error = null

    //   try {
    //     const [userResponse, reposResponse] = await Promise.all([
    //       axios.get(`https://api.github.com/users/${username}`),
    //       axios.get(`https://api.github.com/users/${username}/repos?per_page=5&sort=updated`)
    //     ])

    //     this.user = userResponse.data
    //     this.repos = reposResponse.data
    //     this.addToSearchHistory(username)
    //   } catch (error) {
    //     this.error = error.message || 'Failed to fetch user data'
    //     console.error('Error fetching user:', error)
    //   } finally {
    //     this.loading = false
    //   }
    // },

    // addToSearchHistory(username) {
    //   // 避免重复
    //   if (!this.searchHistory.includes(username)) {
    //     this.searchHistory.unshift(username)
    //     // 限制历史记录数量
    //     if (this.searchHistory.length > 5) {
    //       this.searchHistory.pop()
    //     }
    //     localStorage.setItem('searchHistory', JSON.stringify(this.searchHistory))
    //   }
    // },

    // loadSearchHistory() {
    //   const history = localStorage.getItem('searchHistory')
    //   if (history) {
    //     this.searchHistory = JSON.parse(history)
    //   }
    // }
  }
})    